#include <bits/stdc++.h>
using namespace std ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;
const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;
int arrA[105], arrB[105] ;
int main()
{
fastIO ;
ll t ;
cin >> t ;
while (t--) {
int n, maxA, maxB ;
bool isPossible = true ;
cin >> n ;
for (int i = 0; i < n; i++) {
cin >> arrA[i] ;
}
for (int i = 0; i < n; i++) {
cin >> arrB[i] ;
}
maxA = arrA[n - 1] ;
maxB = arrB[n - 1] ;
for (int i = 0; i < n; i++) {
if ((arrA[i] <= maxA and arrB[i] <= maxB) or (arrA[i] <= maxB and arrB[i] <= maxA)) {
continue ;
}
else {
isPossible = false ;
break ;
}
}
if (isPossible) {
cout << "Yes\n" ;
}
else {
cout << "No\n" ;
}
}
return 0 ;
}
1520A - Do Not Be Distracted | 352A - Jeff and Digits |
1327A - Sum of Odd Integers | 1276A - As Simple as One and Two |
812C - Sagheer and Nubian Market | 272A - Dima and Friends |
1352C - K-th Not Divisible by n | 545C - Woodcutters |
1528B - Kavi on Pairing Duty | 339B - Xenia and Ringroad |
189A - Cut Ribbon | 1182A - Filling Shapes |
82A - Double Cola | 45A - Codecraft III |
1242A - Tile Painting | 1663E - Are You Safe |
1663D - Is it rated - 3 | 1311A - Add Odd or Subtract Even |
977F - Consecutive Subsequence | 939A - Love Triangle |
755A - PolandBall and Hypothesis | 760B - Frodo and pillows |
1006A - Adjacent Replacements | 1195C - Basketball Exercise |
1206A - Choose Two Numbers | 1438B - Valerii Against Everyone |
822A - I'm bored with life | 9A - Die Roll |
1430B - Barrels | 279B - Books |